<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>弹出框实现</title>
    <style>
        .a{
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background-color:rgba(0, 0, 0, .1);
            z-index: 1;
        }
        .hide{
            display: none;
        }
        .a .b{
            width: 600px;
            height: 400px;
            margin: auto;
            position: absolute;
            left: 0;right: 0;
            top: 0;bottom: 0;
            background-color: #fff;
            border-radius: 10px;
        }
        .a .b .c{
            width: 20px;
            height: 20px;
            background-color: #333;
            position: absolute;
            right: 10px;
            top: 10px;
        }
    </style>
</head>
<body>
    <button>登录</button>
    <div class="a hide">
        <div class="b">
            <div class="c"></div>
        </div>
    </div>
    <script>
        let btn  = document.querySelector("button");
        let modal = document.querySelector(".a");
        let closeBtn = document.querySelector(".a .c");
        btn.addEventListener("click",show);
        function show(){
            modal.classList.remove("hide");
        }
        closeBtn.addEventListener("click",hide);
        function hide(){
            modal.classList.add("hide");
        }
    </script>
</body>
</html>